<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>充值管理</title>
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${applicationScope.basePath}/css/nav.css">
    <link href="${applicationScope.basePath}/css/font-awesome.css" rel="stylesheet"/>
    <link href="${applicationScope.basePath}/css/myPage.css" rel="stylesheet"/>
    <script type="text/javascript" src="${applicationScope.basePath}/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="${applicationScope.basePath}/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${applicationScope.basePath}/js/nav.js"></script>
    <style>
        table {
            width: 200px;
            table-layout: fixed; /* 只有定义了表格的布局算法为fixed，下面td的定义才能起作用。 */
        }

        td {
            width: 100%;
            word-break: keep-all; /* 不换行 */
            white-space: nowrap; /* 不换行 */
            overflow: hidden; /* 内容超出宽度时隐藏超出部分的内容 */
            text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记(...) ；需与overflow:hidden;一起使用。*/
        }

        th {
            text-align: center;
        }
    </style>
</head>
<body>
<jsp:include page="header.jsp" flush="true"/>
<div class="row" style="height: 100%;margin-top: -21px;">
    <div class="col-xs-2" style="height: 100%;margin-left: 0;">
        <div class="nav nav-pills nav-stacked">
            <div class="nav-top">
                <div id="mini" style="border-bottom:1px solid rgba(255,255,255,.1)"><img src="${applicationScope.basePath}/images/mini.png"></div>
            </div>
            <ul>
                <li class="nav-item"><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/main"><i
                        class="icon icon-home"></i><span>首页</span></a></li>
                <li class="nav-item">
                    <a style="text-decoration: none;" href="javascript:;"><i
                            class="icon icon-group"></i><span>用户管理</span></a>
                    <ul>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/userpage/1"><span>&emsp;&emsp;用户列表</span></a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a style="text-decoration: none;" href="javascript:;"><i
                            class="icon icon-signal"></i><span>商品管理</span> </a>
                    <ul>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/goodspage/1"><span>&emsp;&emsp;商品列表</span></a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a style="text-decoration: none;" href="javascript:;"><i class="icon icon-th"></i><span>订单管理</span></a>
                    <ul>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/orderspage/1"><span>&emsp;&emsp;订单列表</span></a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a style="text-decoration: none;" href="javascript:;"><i
                            class="icon icon-inbox"></i><span>钱包管理</span></a>
                    <ul>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/purse/page/1"><span>&emsp;&emsp;钱包列表</span></a></li>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/withdrawals/page/1"><span>&emsp;&emsp;提现列表</span></a></li>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/recharge/page/1"><span>&emsp;&emsp;充值列表</span></a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a style="text-decoration: none;" href="javascript:;"><i
                            class="icon icon-fullscreen"></i><span>系统设置</span></a>
                    <ul>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/sys"><span>&emsp;&emsp;发布信息</span></a></li>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/password"><span>&emsp;&emsp;修改密码</span></a></li>
                        <li><a style="text-decoration: none;" href="${applicationScope.basePath}/admin/ipblack"><span>&emsp;&emsp;黑名单IP</span></a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="col-xs-10">
        <ol class="breadcrumb" style="margin-top: 15px;">
            <li><a href="#"><i class="icon-home"></i>首页</a></li>
            <li class="active">充值列表</li>
        </ol>
        <div class="container">
            <!--搜索栏-->
            <form id="wSelectFrom" class="form-inline row" action="${applicationScope.basePath}/admin/recharge/select/1" method="get">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label for="email">用户邮箱</label>
                        <input type="email" maxlength="20" class="form-control" id="email" name="email" value="${_email}"
                               placeholder="">
                    </div>
                    <div class="form-group">
                        <label for="myselected">审核状态：</label><select class="form-control" name="status" id="myselected">
                        <option value="">请选择状态</option>
                        <option value="0">待审核</option>
                        <option value="1">通过</option>
                        <option value="2">未通过</option>
                    </select>
                    </div>
                </div>
                <div class="col-xs-6">
                    <button class="btn btn-success btn-sm" type="submit">查找</button>
                    <button class="btn btn-danger btn-sm" onclick="delSelected();">删除</button>
                </div>
            </form>
            <hr/>
            <div class="panel panel-default">
                <div class="panel-heading">充值列表</div>
                <!--表格显示-->
                <table class="table table-bordered table-hover text-center">
                    <thead>
                    <tr>
                        <th style="width: 50px;"><input type="checkbox" id="selectAllButton"></th>
                        <th style="width: 80px;">序号</th>
                        <th>用户邮箱</th>
                        <th>充值金额</th>
                        <th>时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${info.list}" varStatus="vs" var="item">
                        <tr>
                            <td><input type="checkbox" name="itemIds" value="${item.id}"><input type="text" id="_id"
                                                                                                hidden="hidden"
                                                                                                value="${item.user_id}">
                            </td>
                            <td>${(info.pageNum > 0 ? info.pageNum - 1 : 0) * 10 + vs.count}</td>
                            <td>${item.email}</td>
                            <td>￥${item.recharge}</td>
                            <td>${item.time}</td>
                            <td>
                                <c:if test="${item.status == 0}">
                                    <span class="btn-primary  btn-danger">待审核</span>
                                </c:if>
                                <c:if test="${item.status == 1}">
                                    <span class="btn-primary  btn-info">通过</span>
                                </c:if>
                                <c:if test="${item.status == 2}">
                                    <span class="btn-primary  btn-info">未通过</span>
                                </c:if>
                            </td>
                            <td>
                                <c:if test="${item.status == 0}">
                                    <button onclick="doPassOrUnPass('${item.id}','1','${item.recharge}');" type="button"
                                            class="btn btn-sm btn-warning">通过
                                    </button>
                                    <button onclick="doPassOrUnPass('${item.id}','0','${item.recharge}');" type="button"
                                            class="btn btn-sm btn-info">不通过
                                    </button>
                                </c:if>
                                <c:if test="${item.status != 0}">
                                    --
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
            <div style="text-align: right">
                <div class="pagination">
                    <ul>
                        <li class="active"><a>共${info.pages}页,${info.total}条记录</a></li>
                        <c:if test="${_email == null || _status == null}">
                            <li><a
                                    href="${applicationScope.basePath}/admin/recharge/page/${info.prePage > 1 ? info.prePage : 1}">上一页</a>
                            </li>
                        </c:if>
                        <c:if test="${_email != null && _status != null}">
                            <li><a
                                    href="#" onclick="return selectBy(1);">上一页</a>
                            </li>
                        </c:if>
                        <li class="active"><a>第${info.pageNum <= 0 ? 1 : info.pageNum}页</a></li>
                        <c:if test="${_email == null || _status == null}">
                            <li><a
                                    href="${applicationScope.basePath}/admin/recharge/page/${info.nextPage == 0 ? info.pages : info.nextPage}">下一页</a>
                            </li>
                        </c:if>
                        <c:if test="${_email != null && _status != null}">
                            <li><a onclick="return selectBy(2);"
                                   href="#">下一页</a>
                            </li>
                        </c:if>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
<br/>
<br/>
<div class="footerpanel">
    © 二手交易系统后台 2020
</div>


<script type="text/javascript">

    /*选择模板*/
    $(document).ready(function () {
        let status = "${_status}";
        let $option = $("#myselected").children();
        for (let i = 0; i < $option.length; i++) {
            if ($option[i].value === status) {
                $($option[i]).attr("selected", true);
            } else {
                $($option[i]).attr("selected", false);
            }
        }
    });

    $(function () {

        /*全选*/
        $("#selectAllButton").on("click", function () {
            let $inputs = $("input[name='itemIds']");
            if ($(this).prop("checked")) {
                // 全部选中
                for (let i = 0; i < $inputs.length; i++) {
                    $($inputs[i]).attr("checked", true);
                }
            } else {
                // 全部取消选中
                for (let i = 0; i < $inputs.length; i++) {
                    $($inputs[i]).attr("checked", false);
                }
            }
        });


    });

    /*选择分页*/
    function selectBy(i) {
        let $form = $("#wSelectFrom");
        if(i === 1){
            $form.attr("action", "${applicationScope.basePath}/admin/recharge/select/${info.prePage > 1 ? info.prePage : 1}");
        }
        if(i === 2){
            $form.attr("action", "${applicationScope.basePath}/admin/recharge/select/${info.nextPage == 0 ? info.pages : info.nextPage}");
        }
        $form.submit();
        return false;
    }

    /*删除*/
    function delSelected(){
        if (confirm("确定删除？")) {
            let $inputs = $("input[name='itemIds']");
            // 判断是否有一个选中
            let idList = [];
            let id;
            //查找选中的
            for (let i = 0; i < $inputs.length; i++) {
                // 如果选中
                if ($($inputs[i]).is(':checked')) {
                    id = $($inputs[i]).val();
                    idList.push(id);
                }
            }
            if (idList.length > 0) {
                $.ajax({
                    url: '${applicationScope.basePath}/admin/recharge',
                    type: 'DELETE',
                    data: JSON.stringify(idList),
                    dataType: 'json',
                    contentType: "application/json;charset=UTF-8",
                    success: function (data) {
                        if (data['flag']) {
                            window.location.reload();
                        } else {
                            alert("删除失败");
                        }
                    },
                    error: function () {
                        alert('请求超时或系统出错!');
                    }
                });
            } else {
                alert("请至少选择一项");
            }
        }
    }

    /*审核*/
    function doPassOrUnPass(id, status, recharge) {
        const _id = $("#_id").val();
        const data = '{"id":' + id + ',"user_id":' + _id + ',"status":' + status + ',"recharge":' + recharge + '}';
        if (id) {
            $.ajax({
                url: '${applicationScope.basePath}/admin/recharge',
                type: 'PUT',
                data: data,
                dataType: 'json',
                contentType: "application/json;charset=UTF-8",
                success: function (json) {
                    if (json) {
                        location.reload();
                    } else {
                        alert("审核失败")
                    }
                },
                error: function () {
                    alert('请求超时或系统出错!');
                }
            });
        } else {
            alert("请刷新重试。。。");
        }
    }
</script>
</body>
</html>
